package com.study.clothes.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.study.clothes.pojo.CollectionGoods;

import com.study.clothes.pojo.RespBean;
import com.study.clothes.service.ICollectionGoodsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/collectiongoods")
public class CollectiongoodsController {
    @Autowired
    private ICollectionGoodsService iCollectiongoodsService;
    @GetMapping("/")
    public List<CollectionGoods> collectiongoodsList(){

        return iCollectiongoodsService.list();

    }
    @PostMapping("/")
    public RespBean add(CollectionGoods collectiongoods){

        if (iCollectiongoodsService.save(collectiongoods)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");

    }
    @PutMapping("/")
    public RespBean update(CollectionGoods collectiongoods){
        if (iCollectiongoodsService.updateById(collectiongoods)) {
            return RespBean.success("修改成功");
        }
        return RespBean.error("修改失败");
    }
    @DeleteMapping("/{id}")
    public RespBean deleteCollectiongoods(@PathVariable Integer id){
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("goodsId", id);
        if (iCollectiongoodsService.remove(updateWrapper)) {
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");

    }

}
